﻿using Hicap.AuthorizationServer.Core;
using Hicap.AuthorizationServer.Core.Configuration;
using Hicap.AuthorizationServer.Core.Web;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;

namespace Hicap.AuthorizationServer.EntityFrameworkCore
{
    /* This class is needed to run EF Core PMC commands. Not used anywhere else */

    public class AuthorizationServerDbContextFactory : IDesignTimeDbContextFactory<AuthorizationServerDbContext>
    {
        public AuthorizationServerDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<AuthorizationServerDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            DbContextOptionsConfigurer.Configure(
                builder,
                configuration.GetConnectionString(AuthorizationServerConsts.ConnectionStringName)
            );

            return new AuthorizationServerDbContext(builder.Options);
        }
    }
}